package com.yike.user.service.impl;

import com.yike.user.entity.UserSetting;
import com.yike.user.mapper.UserSettingMapper;
import com.yike.user.service.UserSettingService;
import com.yike.user.param.UserSettingPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用户设置表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-12
 */
@Slf4j
@Service
public class UserSettingServiceImpl extends BaseServiceImpl<UserSettingMapper, UserSetting> implements UserSettingService {

    @Autowired
    private UserSettingMapper userSettingMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveUserSetting(UserSetting userSetting) throws Exception {
        return super.save(userSetting);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateUserSetting(UserSetting userSetting) throws Exception {
        return super.updateById(userSetting);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteUserSetting(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<UserSetting> getUserSettingPageList(UserSettingPageParam userSettingPageParam) throws Exception {
        Page<UserSetting> page = new PageInfo<>(userSettingPageParam, OrderItem.desc(getLambdaColumn(UserSetting::getCreateTime)));
        LambdaQueryWrapper<UserSetting> wrapper = new LambdaQueryWrapper<>();
        IPage<UserSetting> iPage = userSettingMapper.selectPage(page, wrapper);
        return new Paging<UserSetting>(iPage);
    }

}
